﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToPLMX.ViewModels.CUiETPXShellViewModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.ExportToPLMX.Commands;
using System;
using System.IO;
using System.Windows;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.ExportToPLMX.ViewModels;

public class CUiETPXShellViewModel : ObservableObject
{
  private CApExportToPLMXApp m_app;

  public CUiETPXOutputViewModel OutputVm { get; set; }

  public CUiETPXContentViewModel ContentVm { get; set; }

  public CUiETPXExportCommand ExportCommand { get; set; }

  public CUiETPXCloseCommand CloseCommand { get; set; }

  public CUiETPXShellViewModel()
  {
    this.OutputVm = new CUiETPXOutputViewModel();
    this.ContentVm = new CUiETPXContentViewModel();
    this.m_app = new CApExportToPLMXApp(this.OutputVm, this.ContentVm);
    this.ExportCommand = new CUiETPXExportCommand(new Action(this.ExportStudy), new Func<bool>(this.CanExport));
    this.CloseCommand = new CUiETPXCloseCommand(new Action<TxWindow>(this.CloseWindow));
  }

  private bool CanExport()
  {
    return !string.IsNullOrEmpty(this.OutputVm.ExportPath) && this.IsValidDirectory() && this.IsValidExtension() && !string.IsNullOrEmpty(this.OutputVm.PackageName) && this.ContentVm.IsOperationValid;
  }

  private bool IsValidDirectory()
  {
    return Directory.Exists(Path.GetDirectoryName(this.OutputVm.ExportPath));
  }

  private bool IsValidExtension() => Path.GetExtension(this.OutputVm.ExportPath).Equals(".plmx");

  private void ExportStudy()
  {
    if (!this.m_app.ExportStudy())
      return;
    this.ExportCommand.CloseAction();
  }

  private void CloseWindow(TxWindow window) => ((Window) window)?.Close();
}
